// pages/subpackage/notecase/index.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: wx.getStorageSync('TwoPlusTravel').phone || '',
    plateNumber: wx.getStorageSync('TwoPlusTravel-plateNumber') || '',
    messageModi: '',
    Moditit: '',
    Modishow: false,
    money: '0.00'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getMyWallet()
  },
  getMyWallet () {
    let that = this
    util.request('GET', api.getMyWallet, {phone: this.data.phone}).then(function (res) {
      if (Object.keys(res).length) {
        that.setData({
          money: res.money
        })
      }
    })
  },
  onClose () {
    this.setData({
      show: false,
      Modishow: false
    })
  },
  reviseModiBtn (e) {
    console.log(e);
    let tit = e.currentTarget.dataset.tit
    if (tit == '手机号修改') {
      this.setData({
        messageModi: this.data.phone
      })
    }else {
      this.setData({
        messageModi: this.data.plateNumber
      })
    }
    this.setData({
      Moditit: tit,
      Modishow: true
    })
  },
  affirmBtn () {
    let messageModi = this.data.messageModi
    if (messageModi == '') {
      wx.showToast({
        title: '请输入内容',
        icon: 'none'
      })
      return
    }
    let Moditit = this.data.Moditit
    if (Moditit == '手机号修改') {
      var regex = /^1[3-9]\d{9}$/;
      if (!regex.test(messageModi)) {
        wx.showToast({
          title: '手机号码格式有误',
          icon: 'none'
        })
        return
      }
      let TwoPlusTravel = wx.getStorageSync('TwoPlusTravel')
      TwoPlusTravel.phone = messageModi
      wx.setStorageSync('TwoPlusTravel', TwoPlusTravel)

      this.setData({
        Modishow: false,
        phone: messageModi,
        messageModi: ''
      })
    }else {
      wx.setStorageSync('TwoPlusTravel-plateNumber', messageModi)
      this.setData({
        Modishow: false,
        plateNumber: messageModi,
        messageModi: ''
      })
    }
  },
  onModiChange (e) {
    this.setData({
      messageModi: e.detail
    })
  },
  // 发布行程
  ReleaseSchedule (e) {
    let setOut = e.detail.setOut
    let destination = e.detail.destination
    if (setOut.name && destination.name) {
      this.setData({
        setOut: setOut,
        destination: destination,
        show: true
      })
    }
  },
  gotowithdrawDeposit () {
    wx.navigateTo({
      url: '/pages/subpackage/withdrawDeposit/index'
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})